<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>添加电影</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/index.css">
    <link href="${path}/css/updateMovie.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/index.js"></script>
    <script type="text/javascript" rel="script" src="${path}/js/jquery-3.6.4.js"></script>
</head>
<body>
<div class="action  divaction">
    <div class="t">
        添加电影信息
    </div>
    <form method="post" action="${path}/MovieServlet?prom=addMovie" enctype="multipart/form-data" onsubmit="return check()">
        <div class="b2">
            <ul>
                <hr>
                <li>
                    <div class="a2">
                        <img id="moviePirture"  src="${path}/images/tool/jia.png" >
                    </div>
                    <input type="button" value="选择文件" id="buttonx"><input id="file" type="file" multiple="multiple" name="movie_picture">
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影名称-中文</span>
                        <input type="text" placeholder="请输入电影名" class="a4" id="movie_cn_name" name="movie_cn_name"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影名称-外语</span>
                        <input type="text" placeholder="请输入电影名" class="a4" id="movie_fg_name" name="movie_fg_name"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影类型</span>
                    </div>
                    <input type="checkbox" class="a5" name="movie_type" value="爱情"/><span class="a6">爱情</span>
                    <input type="checkbox" class="a5" name="movie_type" value="喜剧"/><span class="a6">喜剧</span>
                    <input type="checkbox" class="a5" name="movie_type" value="动作"/><span class="a6">动作</span>
                    <input type="checkbox" class="a5" name="movie_type" value="剧情"/><span class="a6">剧情</span>
                    <input type="checkbox" class="a5" name="movie_type" value="科幻"/><span class="a6">科幻</span>
                    <input type="checkbox" class="a5" name="movie_type" value="恐怖"/><span class="a6">恐怖</span>
                    <input type="checkbox" class="a5" name="movie_type" value="动画"/><span class="a6">动画</span>
                    <input type="checkbox" class="a5" name="movie_type" value="惊悚"/><span class="a6">惊悚</span>
                    <input type="checkbox" class="a5" name="movie_type" value="犯罪"/><span class="a6">犯罪</span>
                    <input type="checkbox" class="a5" name="movie_type" value="奇幻"/><span class="a6">奇幻</span>
                    <input type="checkbox" class="a5" name="movie_type" value="冒险"/><span class="a6">冒险</span>
                    <input type="checkbox" class="a5" name="movie_type" value="另类"/><span class="a6">另类</span>
                    <span id="typeText"></span>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影地区</span>
                        <input type="text" placeholder="中国大陆" class="a4" id="movie_country" name="movie_country"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影导演</span>
                        <input type="text" placeholder="请填写电影导演" class="a4" id="movie_director" name="movie_director"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影主演</span>
                        <input type="text" placeholder="请填写电影主演" class="a4" id="movie_actor" name="movie_actor"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">电影片长</span>
                        <input type="text" placeholder="请填写电影片长(单位:分钟)" class="a4" id="movie_duration" name="movie_duration"/>
                    </div>
                    </p>
                </li>
                <li>
                    <p>
                    <div class="a3">
                        <span class="b1">上映时间</span>
                        <input type="date" placeholder="请输入电影上映日期" class="a4" id="movie_releaseDate" name="movie_releaseDate"/>
                    </div>
                    </p>
                </li>
                <li>
                    是否上映:
                    <input type="radio" name="movie_state" value="1" >在线
                    <input type="radio" name="movie_state" value="2" >预售
                    <input type="radio" name="movie_state" value="3" >下架
                </li>
                <li>
                    <input type="submit" value="添加" class="a9">
                    <input type="button" value="返回" class="a9" onclick="xadmin.close()">
                </li>
            </ul>
        </div>
    </form>
</div>
<script>
    $("#file").change(function () {
        //获取文件名称
        var url=document.getElementById('file').files[0].name;
        $("#moviePirture").attr("src","${path}/images/moviePicture/"+url);
        //获取文件全部路径
        var urlPath=document.getElementById('file').value;
    });
    function check(){
        let file=$("#file").val();
        let movie_cn_name=$("#movie_cn_name").val();
        let movie_fg_name=$("#movie_fg_name").val();
        let movie_country=$("#movie_country").val();
        let movie_director=$("#movie_director").val();
        let movie_actor=$("#movie_actor").val();
        let movie_duration=$("#movie_duration").val();
        let movie_releaseDate=$("#movie_releaseDate").val();
        let movie_type=document.getElementsByName("movie_type");
        var arr = [];
        for(var i=0,len = movie_type.length;i<len;i++){
            arr.push(movie_type[i]);
        }
        if (file==""||file==null){
            alert("电影海报不能为空!");
            return false;
        }
        if (movie_cn_name==""||movie_cn_name==null){
            alert("电影名（中文）不为空!");
            return false;
        }else if (movie_fg_name==""||movie_fg_name==null){
            alert("电影名（英文）不为空");
            return false;
        }else if (movie_country==""||movie_country==null){
            alert("电影地区不为空");
            return  false;
        }else if (movie_director==""||movie_director==null){
            alert("电影导演不为空");
            return false;
        }else if (movie_actor==""||movie_actor==null){
            alert("电影群演不为空");
            return false;
        }else if (movie_duration==""||movie_duration==null){
            alert("电影片长不为空");
            return false;
        }else if (movie_releaseDate==""||movie_releaseDate==null){
            alert("电影上映时间不能为空");
            return false;
        }
        //王玲娟-2023/09/05——电影类型非空验证、是否上映非空验证
        var checkBoxes=$(".a5");
        var isChecked=false;
        checkBoxes.each(function () {
            if(this.checked){
                isChecked=true;
            }
        });
        if(!isChecked){
            alert("至少选一个电影类型");
            return false;
        }

        var radioNames=$("input[name='movie_state']");
        var isRadioChecked=false;
        radioNames.each(function (){
            if(this.checked){
                isRadioChecked=true;
            }
        });
        if(!isRadioChecked){
            alert("请选择电影状态");
            return false;
        }
        return true;

    }
  /*  function Addsumbit(){
        $.post("${path}/MovieServlet?prom=addMovie",
            {movie_picture:file,movie_cn_name:movie_cn_name,movie_fg_name:movie_fg_name,
                movie_type:movie_type,movie_country:movie_country,movie_director:movie_director,
                movie_actor:movie_actor,movie_duration:movie_duration,
                movie_releaseDate:movie_releaseDate,movie_state:movie_state},
            function (result){
                if(result>0){
                    xadmin.close();
                }
            },"text")
    }*/
</script>
</body>
</html>
